home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-01 | 3.7 KB | 183 lines | [TEXT/CWIE] |
- // Count
- // version 1.0.1
- // ported to THINK by Ken Long <kenlong@netcom.com>
- // updated for THINK 7 and CW7 on 951201
-
- /* count - By: Jeff Beadles jeff@quark.WV.TEK.COM
-
-
- This program will count from the starting number to the stop
- number, using the character 'fs' as the field seperator.
-
- Note, that fs may be in several forms:
- -A will use the letter 'A'
- -- will use a '-' as fs, and
- -\011 will use a tab (Octal 011) as the fs. (sh does the expansion.)
-
- Bugs may be sent to me if desired.
- Please keep your flames to yourself. What do you expect for free?
- */
-
- /*
- # Makefile for count. This is a little overkill, but what the heck.
- # (This is public domain too!)
- # Written by: Jeff Beadles
- # jeff@quark.WV.TEK.COM ...tektronix!quark.wv!jeff
- #
-
- CC = cc
- CFLAGS =
-
- #For the executable file
- BINDIR=/usr/bin
-
- count: count.c Makefile
- $(CC) $(CFLAGS) count.c -o count
-
- install: count
- -strip count
- cp count ${BINDIR}/count
- chmod 755 ${BINDIR}/count
-
- clean:
- rm -f *.o core a.out
-
- clobber: clean
- rm -f count
-
- */
-
- /*
- .\"
- .\" @(#)count 1.0 05/09/89
- .\"
- .TH COUNT 1 "09 MAY 1989"
- .UC 4
- .SH NAME
- count \- count numbers from a start to a stop point.
- .SH SYNOPSIS
- .B count [-c] start stop
- .SH DESCRIPTION
- .I Count
- will count thru an integer sequence of numbers from
- .I Start
- to
- .I Stop
- with a newline after each number.
-
- Optionally,
- .I -c
- may be on the command line. This may be in one of two forms.
- .I -$
- will put a
- .I $
- between each number.
- .I -040
- will put a space (Octal
- .I 040
- ) between each number.
-
- .SH AUTHOR
- Jeff Beadles jeff@quark.WV.TEK.COM
- */
-
- /* Count.c Released into the public domain on 05/09/89
- * Written by: Jeff Beadles jeff@quark.WV.TEK.COM
- * or ...!tektronix!quark.WV!jeff
- *
- * NOTE: This program is not supported by Tektronix, Inc.
- *
- * This program will count from the starting number to the stop
- * number, using the character 'fs' as the field seperator.
- * Note, that fs may be in several forms:
- * -A will use the letter 'A'
- * -- will use a '-' as fs, and
- * -\011 will use a tab (Octal 011) as the fs. (sh does the expansion.)
- *
- * Bugs may be sent to me if desired.
- * Please keep your flames to yourself. What do you expect for free?
- *
- */
-
-
- #include <stdio.h>
- #include <ctype.h>
- #include <console.h>
-
- /*
- * Default field separator
- */
-
- #ifndef FS
- #define FS '\n'
- #endif
-
- int main (int argc, char **argv)
- {
- void usage();
- int oatc();
- int start = 0; /* Start count */
- int stop = 0; /* Stop count */
- int pos = 1; /* Position in command line for parsing */
- char fs = FS; /* Field Separator */
-
- argc = ccommand (&argv);
-
- if ( argc < 2)
- usage(argv[0]); /* Does not return */
-
- if ( argv[1][0] == '-' ) {
- if ( (isdigit(argv[1][1])) && (strlen(argv[1]) == 4) )
- fs=oatc(argv[1] + 1);
- else
- fs = argv[1][1];
- pos++; /* On to the next arg... */
- }
- start = atoi(argv[pos++]); /* Start here, and... */
-
- if ( argc <= pos)
- usage(argv[0]); /* Does not return */
-
- stop = atoi(argv[pos]); /* Stop here. */
- if ( start >= stop) /* Are they brain damaged? */
- {
- fprintf(stderr,"Error: START must be less than STOP\n");
- exit(-2);
- }
-
- /*
- Yes, this is it. It even prints a '\n' when done, if the fs != '\n' (Wow)
- */
- while ( start <= stop )
- printf("%d%c",start++,( (start != stop) ? fs : '\n' ) );
- }
-
- /*
- Can you figure out this function with no comments? Sure, you can.
- */
- void usage (char *program)
- {
- fprintf(stderr,"Usage: %s [ -c] start stop\n",program);
- exit(-1);
- }
-
- /*
- * octal ascii to char
- */
-
- int oatc (char *str)
- {
- int retval=0;
- int pos=0;
- int tmp=0;
- int loop;
- static int table[] = { 1, 8, 64 }; /* Powers of 8, to avoid POW */
-
-
- for(loop=strlen(str) - 1; loop >= 0; loop--)
- retval += ( (str[loop] - '0') * table[pos++] );
-
- return((char)retval);
- }
-
-